AgreeAddFormCtl = Ext.extend(FormCtl, {

	configItems : function(config) {

		var s = cf.getC('s');

		var customerUrl = s.getUrl({
					resource : 'customer.do',
					act : 'namelist'
				});

		var items = {};
		items['id'] = this.getHiddenField('ID', 'id', true);

		var stmBox = this.getCombobox('客户公司名称', 'customername', false,
				customerUrl);

		stmBox.cbbStore.load();
		stmBox.on('select', this.customerSelect, this);
		items['customername'] = stmBox;

		var connectorUrl = s.getUrl({
					resource : 'connector.do',
					act : 'readForSelect'
				});

		items['contactor'] = this.getCombobox('客户联系人', 'contactor', false,
				connectorUrl);

		var regionsUrl = s.getUrl({
					resource : 'regions.do',
					act : 'r'
				});

		items['region'] = this.getCombobox('项目区域', 'region', false, regionsUrl);
		items['country'] = this.getCombobox('项目国家', 'country', false,
				regionsUrl);
		items['city'] = this.getCombobox('项目城市', 'city', false, regionsUrl);

		items['size'] = this.getCombobox('项目规模', 'size', true, {
					items : [{
								key : '1～2种建筑',
								value : '1～2种建筑'
							}, {
								key : '3～6种建筑',
								value : '3～6种建筑'
							}, {
								key : '7～10种建筑',
								value : '7～10种建筑'
							}, {
								key : '10种以上',
								value : '10种以上'
							}]
				});

		var currencyUrl = s.getUrl({
					resource : 'currency.do',
					act : 'readAllForSelect'
				});

		items['currency'] = this.getCombobox('签单币种', 'currency', false,
				currencyUrl, 'key');

		items['signdate'] = this.getDateField('签单日期 ', 'signdate', true);

		items['dataRdyTime'] = this.getDateField('资料提供日期', 'dataRdyTime', true);
		items['finishTime'] = this.getDateField('完成日期', 'finishTime', true);

		items['cost'] = this.getTextField('合同总金额本币', 'cost', true);
		items['cost'].setValue('0');

		items['requirements'] = this.getTextArea('制作具体要求', 'requirements', 80,
				150);
		items['proname'] = this.getTextField('项目名称', 'proname', true);

		this.items = items;

		var groupItems = [items['id'], {
			columnWidth : .3,
			layout : 'form',// 第一列里面内容就是form排序了,从上到下
			items : [items['proname'], items['region'], items['signdate'],
					items['currency'], items['size']]
		}, {
			columnWidth : .4,
			layout : 'form',
			items : [items['customername'], items['country'],
					items['dataRdyTime'], items['cost']]
		}, {
			columnWidth : .3,
			layout : 'form',
			items : [items['contactor'], items['city'], items['finishTime'],
					items['requirements']]
		}];

		items['region'].cbbStore.baseParams = {
			level : 1
		};

		items['region'].cbbStore.load();

		items['region'].on('select', this.selectRegion, this);
		items['country'].on('select', this.selectCountry, this);

		items['currency'].cbbStore.load();

		config.items = groupItems;

		return config;

	},
	getCommonConfig : function() {

		var config = {
			split : true,
			autoScroll : true,
			region : 'center',
			layout : 'column',
			labelAlign : 'right',
			labelWidth : 100,
			frame : true
		};

		return config;

	},
	configButtons : function(config) {

		return config;

	},
	getFormHeight : function() {

		return 280;

	},
	getSubmitUrl : function() {

		return 'contract.do?m=save';

	},
	getLoadUrl : function() {

		return 'user.do?m=read';

	},
	submitSuccess : function(from, action) {
		var cigc = cf.getC('usrmger');
		cigc.reload();
	},
	getLoadParams : function(record) {
		return {
			id : record.get('id')
		}

	},
	configReader : function(config) {

		config.reader = new Ext.data.JsonReader({
					root : 'items'
				}, [{
							name : 'username',
							mapping : 'username',
							type : 'string'
						}, {
							name : 'password',
							mapping : 'password',
							type : 'string'
						}, {
							name : 'departmentid',
							mapping : 'departmentid',
							type : 'string'
						}])

		return config;

	},
	customerSelect : function(c, r, i) {

		this.customerRecord = r;
		var items = this.items;

		items['contactor'].cbbStore.load({
					params : {
						customerid : r.get('key')
					}
				});

	},
	saveSuccess : function() {

	},
	submitSuccess : function(from, action) {
		// Ext.example.msg('保存成功', '添加级别成功！');
		var aigc = cf.getC('aigc');
		aigc.reload();
	},
	getParams : function(config) {

		var items = this.getAllItems();

		var params = {
			itemlist : Ext.encode(items)
		};

		var cr = this.customerRecord;
		if (cr) {
			var customerid = cr.get('key');
			params.customerid = customerid;
		}

		config.params = params

		return config;

	},
	getAllItems : function() {

		var acgc = cf.getC('acgc');

		var recordls = acgc.getAllRecord();

		return recordls;

	},
	getCbbStore : function(config, islocal, data) {

		var storeConfig = {
			root : "items",
			fields : ["key", "value"]
		}
		if (!islocal) {
			storeConfig.url = data;
		}

		var dataStore = new Ext.data.JsonStore(storeConfig);

		if (islocal) {
			dataStore.loadData(data);
		}

		config.valueField = 'key';
		config.displayField = 'value';

		config.store = dataStore; // [['f','Foo'],['b','Bar']];

		return config;

	},
	selectRegion : function(c, r, i) {

		var record = r;

		var items = this.items;

		items['country'].cbbStore.baseParams = {
			level : 2
		};

		items['country'].cbbStore.load({
					params : {
						parentid : r.get('key')
					}
				});

		items['country'].reset();
		items['city'].reset();

	},
	selectCountry : function(c, r, i) {

		var record = r;

		var items = this.items;

		items['city'].cbbStore.baseParams = {
			level : 3
		};

		items['city'].cbbStore.load({
					params : {
						parentid : r.get('key')
					}
				});
		items['city'].reset();

	}

});